Skip to content

Conversation

@drculhane
Copy link
Contributor

@drculhane drculhane commented Dec 22, 2025

Closes #5170.

This adds overloads to reshape.

It also fixes a bug in test_flatten_multidim. The expression a.reshape(2,2,size/4) has been changed to a.reshape(2,2,size//4). The reason is that size/4 is interpreted as a float, and floats aren't allowed in a shape. This is consistent with numpy.

Copy link
Contributor

@ajpotts ajpotts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this one!

Copy link
Collaborator

@1RyanK 1RyanK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

def reshape(self, *shape: int_scalars) -> pdarray: ...

@overload
def reshape(self, shape: pdarray) -> pdarray: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add an @overload for numpy arrays?

In [18]: shape_np = np.array([6, 4], dtype=np.int64)
    ...: try:
    ...:     a.reshape(shape_np)
    ...: except Exception as e:
    ...:     print(type(e).__name__, e)
    ...: 
TypeError type of argument "shape"[0] must be one of (int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, Sequence, pdarray); got numpy.ndarray instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea but it could also be a separate ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

overloads to reshape function

3 participants